package org.zxyj.core.utils;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

/**
 * 数组工具类
    * @ClassName: ArrayUtil
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @author Administrator
    * @date 2016年2月4日
    *
 */
public class ArrayUtil {
	public static boolean checkIntInInts(int[] results, int i) {
        if (!ArrayUtils.isEmpty(results)) {
            for (Integer integer : results) {
                if (integer > i) {
                    return true;
                }
            }
        }
        return false;
    }
	
	/**
    * 验证数组中是否包含不为空的内容
    * @param strings
    * @return
    */
   public static boolean checkStringsAllNull(String...strings){
       if (!ArrayUtils.isEmpty(strings)) {
           for (String string : strings) {
               if (StringUtils.isNotEmpty(string)) {
                   return true;
               }
           }
       }
       return false;
   }
   
   /**
    * 将Integer类型数组转换成为Long类型数组
    * @param orgArrays
    * @return
    */
   public static Long[] integersToLongs(Integer[] orgArrays){
       if (!ArrayUtils.isEmpty(orgArrays)) {
           Long[] results = new Long[orgArrays.length];
           for (int i = 0; i < orgArrays.length; i++) {
               results[i] = new Long(orgArrays[i]);
           }
           return results;
       }
       return null;
   }
   
   /**
    * 将String类型数组，转换成为Long类型数组
    * @param orgArrays
    * @return
    */
   public static Long[] stringsToLongs(String[] orgArrays){
       if (!ArrayUtils.isEmpty(orgArrays)) {
           Long[] results = new Long[orgArrays.length];
           for (int i = 0; i < orgArrays.length; i++) {
               results[i] = new Long(orgArrays[i]);
           }
           return results;
       }
       return null;
   }
   
   /**
    * 将对象数组转成字符串
    * @param array
    * @return
    */
   public static String objectsToStrings(Object[] array,String sepSign) {
       if (array != null && array.length > 0) {
           String result = "";
           for (int i = 0; i < array.length; i++) {
               if (i==0) {
                   result = array[0].toString();
               }else {
                   result = result+sepSign+array[i];
               }
           }
           return result;
       }
       return null;
   }
   
   /**
    * 验证字符串数组中是否存在字符串
    * @param strs
    * @param str
    * @return Boolean
    */
   public static Boolean checkStringInStrings(String[] strs, String str) {
       if (strs != null && strs.length > 0) {
           for (String string : strs) {
               if (string.equals(str)) {
                   return true;
               }
           }
       }
       return false;
   }
   
   /**
    * 对象数组转成字符数组
    * @param objArray
    * @return
    */
   public static String[] objectsToStrings(Object[] objArray) {
       if (!ArrayUtils.isEmpty(objArray)) {
           String[] strArray = new String[objArray.length];
           for (int i = 0; i < objArray.length; i++) {
               strArray[i] = (String) objArray[i];
           }
           return strArray;
       }
       return null;
   }
   
   /**
    * 将字符串数组中的元素合并成为一个字符串
    */
   public static String comb2Str(String[] strs, String sign) {
       String combStr = "";
       if (strs != null && strs.length > 0) {
           for (int i = 0; i < strs.length; i++) {
               combStr = strs[i] + sign + combStr;
           }
       }
       return combStr;
   }
}
